#ifndef MYBUTTON_H
#define MYBUTTON_H

#include <QWidget>

class MyButton : public QWidget
{
    Q_OBJECT

    Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)

    Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)

    Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)

public:
    MyButton(QWidget *parent = 0);
    QColor color() const
    {
        return m_color;
    }
    QString text() const
    {
        return m_text;
    }

    int fontSize() const
    {
        return m_fontSize;
    }

public slots:
    void setColor(QColor color)
    {
        if (m_color == color)
            return;

        m_color = color;
        update();
        emit colorChanged(m_color);
    }
    void setText(QString text)
    {
        if (m_text == text)
            return;

        m_text = text;
        update();
        emit textChanged(m_text);
    }

    void setFontSize(int fontSize)
    {
        if (m_fontSize == fontSize)
            return;

        m_fontSize = fontSize;
        update();
        emit fontSizeChanged(m_fontSize);
    }

signals:
    void colorChanged(QColor color);
    void textChanged(QString text);
    void fontSizeChanged(int fontSize);
    void clicked();  // 添加自定义的clicked信号

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;

private:
    QColor m_color;
    QString m_text;
    int m_fontSize;
};

#endif // MYBUTTON_H
